package codeRandomThoughts.Test343整数拆分;


public class Solution2 {
    public static int integerBreak(int n) {
        //dp[i]:拆分i能获得的最大乘积为dp[i]
        int[] dp = new int[59];

        //初始化
        dp[1] = 1;
        dp[2] = 1;
        dp[3] = 2;

        for (int i = 4; i <= n; i++) {
            for (int j = 2; j <= i / 2; j++) {
                int part1 = Math.max(dp[j], j);
                int part2 = Math.max(dp[i - j], i - j);
                dp[i] = Math.max(dp[i], part1 * part2);
            }
        }

        return dp[n];
    }

}
